package leetcode20211007;



/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LUYAO
 * Date: 2021-10-07
 * Time: 17:04
 */

// Definition for singly-linked list.
class ListNode {
    int val;
    ListNode next;
    ListNode(int x) { val = x; }
}

public class RemoveListNode {
    public static void main(String[] args) {

    }
}

class Solution {
    public ListNode deleteNode(ListNode head, int val) {
        if(head == null) return null;
        if(head.val == val) return head.next;
        ListNode temp = head;
        while(temp.next != null && temp.next.val != val){
            temp = temp.next;
        }
        if(temp.next != null) {
            temp.next = temp.next.next;
        }
        return head;

    }
}
